//
// Created by shenbin on 2022/5/1.
// https://leetcode.cn/problems/group-anagrams/
//

#ifndef ALGORITHM_TRAINNING_C03_LC49_H
#define ALGORITHM_TRAINNING_C03_LC49_H

#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

/**
 * 分组和哈希具有相似性，都是从一个信息到另一个信息的映射；
 *
 */
class LeetCode49 {
public:
    vector<vector<string>> groupAnagrams(vector<string> &strs) {
        unordered_map<string, vector<string>> groups;
        for (const string &s: strs) {
            string copy = s;
            sort(copy.begin(), copy.end());
            groups[copy].push_back(s);
        }
        vector<vector<string>> ans;
        for (const pair<string, vector<string>> &g: groups) {
            ans.push_back(g.second);
        }
        return ans;
    }

private:

};

#endif //ALGORITHM_TRAINNING_C03_LC49_H
